package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
@SuppressWarnings("all")
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    //线索跟进记录
    @Override
    public void addClueTrackRecord(TbClueTrackRecord tbClueTrackRecord) {
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        //添加线索跟进记录
        tbClueTrackRecordMapper.addClueTrackRecord(tbClueTrackRecord);
        //修改线索状态
        tbClueTrackRecordMapper.upDateClueStatus(tbClueTrackRecord.getClueId());
    }

    //查询线索跟进记录
    @Override
    public List<TbClueTrackRecord> selectByClueId(Long clueId) {
        return tbClueTrackRecordMapper.selectByClueId(clueId);
    }

    @Override
    public void upDateClueByClueId(Map tbClueTrackRecord) {

        Long clueId = (Long) tbClueTrackRecord.get("clueId");
        Integer falseCount = tbClueTrackRecordMapper.selectClueFalseCount(clueId);

        if (falseCount<2){
            tbClueTrackRecordMapper.upDateClueByClueId(tbClueTrackRecord);
            falseCount=falseCount+1;
            tbClueTrackRecordMapper.upDateClueSatues(clueId, falseCount);

        }else {
            tbClueTrackRecordMapper.deleteByClueIdAfter(clueId);
        }



    }
}
